package com.example.second_app;

// 导入必要的类
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

    private TextView textView;
    private Handler handler;

    @SuppressLint("HandlerLeak")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 设置对应的布局文件
        setContentView(R.layout.activity_main);

        // 初始化TextView组件
        textView = findViewById(R.id.textView);

        // 设置按钮点击监听器
        Button button1 = findViewById(R.id.button1);
        button1.setOnClickListener(v -> textView.setText("ACTIVITY作为监听器"));

        Button button2 = findViewById(R.id.button2);
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                textView.setText("内部类作为监听器");
            }
        });

        // 匿名内部类作为监听器
        findViewById(R.id.button3).setOnClickListener(v -> textView.setText("匿名内部类作为监听器"));

        // Lambda表达式作为监听器
        findViewById(R.id.button4).setOnClickListener(v -> textView.setText("LAMBDA表达式作为监听器"));

        // 外部类作为监听器
        Button button5 = findViewById(R.id.button5);
        button5.setOnClickListener(new ExternalListener());

        // 监听器绑定到标签
        Button button6 = findViewById(R.id.button6);
        button6.setOnClickListener(v -> textView.setText("监听器绑定到标签"));

        // 显示系统信息
        Button button7 = findViewById(R.id.button7);
        button7.setOnClickListener(v -> {
            Intent intent = new Intent(MainActivity.this, ConfigurationTest.class);
            startActivity(intent);
        });

        // 显示进度条
        Button button8 = findViewById(R.id.button8);
        button8.setOnClickListener(v -> {
            // 使用Intent跳转到ProgressDialogTest Activity
            Intent intent = new Intent(MainActivity.this, ProgressDialogTest.class);
            startActivity(intent);
        });

        // 更新进度的Handler
        handler = new Handler(){
            @Override
            public void handleMessage(Message msg) {
                // 根据消息更新进度
                if(msg.what == 0x111){
                    int progress = msg.arg1;
                    // 更新进度逻辑，例如更新进度条或TextView
                }
            }
        };
    }

    // 外部类作为监听器
    private class ExternalListener implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            textView.setText("外部类作为监听器");
        }
    }
}